(function(){
    class Food{
        constructor(box, initial){
            initial = initial instanceof Object ? initial : {};
            this.width = initial.width || 10;
            this.height = initial.height || 10;
            this.maxX = box.clientWidth / this.width -1;
            this.maxY = box.clientHeight / this.height -1;
            this.x = (initial.x || tools.getRandomNumber(0,this.maxX));
            this.y = initial.y || tools.getRandomNumber(0,this.maxY);
            this.backgroundColor = initial.backgroundColor || 'grey';
        }
        render(box){
            this.ele = document.createElement('span');

            this.ele.style.position = 'absolute';
            this.ele.style.width = this.width+'px';
            this.ele.style.height = this.height+'px';
            this.ele.style.left = (this.width * this.x) +'px';
            this.ele.style.top = (this.height * this.y) +'px';
            this.ele.style.borderRadius = '50%';
            this.ele.style.background = this.backgroundColor;

            box.appendChild(this.ele);
        }
        update(){
            this.x = tools.getRandomNumber(0, this.maxX);
            this.y = tools.getRandomNumber(0, this.maxY);
        }
        remove(box){
            box.removeChild(this.ele);
        }
    }
    window.Food = Food;
})();